import java.util.ArrayList;
import java.util.List;

/**
 * 公司实现类-有部门作为子节点
 * @author liaosh
 * @date 2022-10-19 23:02
 */
public class ConcreteCompany extends Company {

    private List<Company> children;

    public ConcreteCompany(String name) {
        super(name);
        children = new ArrayList<>();
    }

    @Override
    public void add(Company company) {
        children.add(company);
    }

    @Override
    public void remove(Company company) {
        children.remove(company);
    }

    @Override
    public void display(int depth) {
        for (int i = 0; i < depth; i++) {
            System.out.print('-');
        }
        System.out.print(name);
        System.out.println();
        for (Company child : children) {
            child.display(depth + 2);
        }
    }

    @Override
    public void lineOfDuty() {
        for (Company child : children) {
            child.lineOfDuty();
        }
    }
}
